package fun.wlfj.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import fun.wlfj.factory.CashSystemFactory;
import fun.wlfj.vo.User;

/**
 * Servlet implementation class CreatePayServlet
 */
@WebServlet("/CreatePayServlet")
public class CreatePayServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CreatePayServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.getWriter().append("Do not request me directly! :D");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String UserName = request.getParameter("UserName");
		if(UserName != null && UserName.length() > 0) {
			User u = new User(UserName, null);
			int PayListID =  CashSystemFactory.getPayListDao(u).makePayList();
			if(u.getUserID() > 0) {
				request.getSession().setAttribute("NewPayListID", PayListID);
				request.getSession().setAttribute("User", u);
			}
		}
		
		response.sendRedirect("makePay.jsp");
	}

}
